#coding=utf-8

from greenlet import greenlet

def test1():
    print 12
    gr2.switch()
    print 34
    gr2.switch()

def test2():
    print 56
    gr1.switch()
    print 78
    gr1.switch()

if __name__ =="__main2__":
    gr1 = greenlet(test1)
    gr2 = greenlet(test2)
    gr1.switch()


#==================gevent=======================
import gevent

def foo():
    print 'running the foo'
    gevent.sleep(0)
    print 'switch to foo again'

def bar():
    print 'switch to and running in  bar'
    gevent.sleep(0)
    print 'witch to bar again'

if __name__=='__main__':
    gevent.joinall([
        gevent.spawn(foo),
        gevent.spawn(bar),
    ])


